package com.stylefeng.guns.modular.pay.payment.jft.api;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.google.common.base.Strings;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.MD5Utils;
import com.stylefeng.guns.core.util.RandomStringGenerator;


/**
 * 商户注册
 * @author DevinYang
 * @date 2018年8月15日  
 *
 */
@JsonInclude(Include.NON_NULL)
public class ApiNotifyRsponse {
	// 响应头
	public String version = "1.0"; // 业务响应码
	public String charset = "UTF-8"; // 返回信息描述
	public String signType="MD5";
	public String respTime=DateUtil.getAllTime(); // 响应时间
	public String respCode; // 响应代码
	public String respMsg; // 响应描述
	public String sign;
	private String nonceStr = RandomStringGenerator.getRandomStringByLength(32);//32位随机字符串

	//业务参数
	private String chMerCode;			//商户编号
	private String orderCode;
	private String platOrderCode;	
	private String tranAmount;
	private String tranTime;
	private String chSerialNo;
	private String tranStatus;

	
	public ApiNotifyRsponse() {
		// TODO Auto-generated constructor stub
	}
	
	public ApiNotifyRsponse(String code,String msg,String key) {
		this.respCode = code;
		this.respMsg =msg; 
		if (!Strings.isNullOrEmpty(key)) {
			this.sign = MD5Utils.getSign(toMap(), key);
		}
	}
	
	
	
	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}

	public String getSignType() {
		return signType;
	}

	public void setSignType(String signType) {
		this.signType = signType;
	}

	public String getRespTime() {
		return respTime;
	}

	public void setRespTime(String respTime) {
		this.respTime = respTime;
	}

	public String getRespCode() {
		return respCode;
	}

	public void setRespCode(String respCode) {
		this.respCode = respCode;
	}

	public String getRespMsg() {
		return respMsg;
	}

	public void setRespMsg(String respMsg) {
		this.respMsg = respMsg;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getNonceStr() {
		return nonceStr;
	}

	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}

	public String getChMerCode() {
		return chMerCode;
	}

	public void setChMerCode(String chMerCode) {
		this.chMerCode = chMerCode;
	}

	public String getOrderCode() {
		return orderCode;
	}

	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}

	public String getPlatOrderCode() {
		return platOrderCode;
	}

	public void setPlatOrderCode(String platOrderCode) {
		this.platOrderCode = platOrderCode;
	}

	public String getTranAmount() {
		return tranAmount;
	}

	public void setTranAmount(String tranAmount) {
		this.tranAmount = tranAmount;
	}

	public String getTranTime() {
		return tranTime;
	}

	public void setTranTime(String tranTime) {
		this.tranTime = tranTime;
	}

	public String getChSerialNo() {
		return chSerialNo;
	}

	public void setChSerialNo(String chSerialNo) {
		this.chSerialNo = chSerialNo;
	}

	public String getTranStatus() {
		return tranStatus;
	}

	public void setTranStatus(String tranStatus) {
		this.tranStatus = tranStatus;
	}

	public Map<String, String> toMap() {
		Map<String, String> map = new HashMap<String, String>();
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			Object obj;
			try {
				obj = field.get(this);
				if (obj != null) {
					map.put(field.getName(), (String) obj);
				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return map;
	}
}
